package com.itheima.user.web;

import com.itheima.user.domain.JdbcProperties;
import com.itheima.user.domain.User;
import com.itheima.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
//热部署注解
//@RefreshScope
public class UserController {

    @Autowired
    private UserService userService;
    @Value("${server.port}")
    private int port;

    @GetMapping("/{id}")
    public User findById(@PathVariable("id") Long id) {
        User user = userService.findById(id);
        user.setUsername(user.getUsername()+"::"+port);
        return user;
    }
//    @Value("${jdbc.username}")
//    private String  username;
//    @Value("${jdbc.password}")
//    private String  password;
    @Autowired
    private JdbcProperties jdbcProperties;
    @GetMapping("/config")
    public String config() {
        return jdbcProperties.getUsername()+"::"+jdbcProperties.getPassword();
    }
}
